/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.tor.tribes.types;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "DSUnits")
public class DSUnit implements Serializable {

    private static final long serialVersionUID = 10L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String plainName = null;
    private String name = null;
    private double wood = 0;
    private double stone = 0;
    private double iron = 0;
    private double pop = 0;
    private double speed = 0;
    private double attack = 0;
    private double defense = 0;
    private double defenseCavalry = 0;
    private double defenseArcher = 0;
    private double carry = 0;
    private double buildTime = 0;

    public DSUnit() {
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    public String getPlainName() {
        return plainName;
    }

    public void setPlainName(String name) {
        this.plainName = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getWood() {
        return wood;
    }

    public void setWood(double wood) {
        this.wood = wood;
    }

    public double getStone() {
        return stone;
    }

    public void setStone(double stone) {
        this.stone = stone;
    }

    public double getIron() {
        return iron;
    }

    public void setIron(double iron) {
        this.iron = iron;
    }

    public double getPop() {
        return pop;
    }

    public void setPop(double pop) {
        this.pop = pop;
    }

    public double getSpeed() {
        return speed;
    }

    public void setSpeed(double speed) {
        this.speed = speed;
    }

    public double getAttack() {
        return attack;
    }

    public void setAttack(double attack) {
        this.attack = attack;
    }

    public double getDefense() {
        return defense;
    }

    public void setDefense(double defense) {
        this.defense = defense;
    }

    public double getDefenseCavalry() {
        return defenseCavalry;
    }

    public void setDefenseCavalry(double defenseCavalry) {
        this.defenseCavalry = defenseCavalry;
    }

    public double getDefenseArcher() {
        return defenseArcher;
    }

    public void setDefenseArcher(double defenseArcher) {
        this.defenseArcher = defenseArcher;
    }

    public double getCarry() {
        return carry;
    }

    public void setCarry(double carry) {
        this.carry = carry;
    }

    public boolean isFarmUnit() {
        return getCarry() > 0 || (getPlainName() != null && getPlainName().equals("spy"));
    }

    public boolean isInfantry() {
        String plain = getPlainName();
        if (plain == null) {
            return false;
        }
        return plain.equals("spear") || plain.equals("sword") || plain.equals("archer") || plain.equals("axe");
    }

    public boolean isCavalry() {
        String plain = getPlainName();
        if (plain == null) {
            return false;
        }
        return plain.equals("spy") || plain.equals("light") || plain.equals("marcher") || plain.equals("heavy");
    }

    public boolean isOther() {
        return !isInfantry() && !isCavalry();
    }

    public boolean isDefense() {
        String plain = getPlainName();
        if (plain == null) {
            return false;
        }
        return plain.equals("spear") || plain.equals("sword") || plain.equals("archer") || plain.equals("spy") || plain.equals("heavy") || plain.equals("catapult");
    }

    public boolean isOffense() {
        String plain = getPlainName();
        if (plain == null) {
            return false;
        }
        return plain.equals("axe") || plain.equals("spy") || plain.equals("light") || plain.equals("marcher") || plain.equals("ram") || plain.equals("catapult");
    }

    public boolean isSpecial() {
        return (!isDefense() && !isOffense());
    }

    public boolean isSpy() {
        String plain = getPlainName();
        if (plain == null) {
            return false;
        }
        return plain.equals("spy");
    }

    public boolean isSnob() {
        String plain = getPlainName();
        if (plain == null) {
            return false;
        }
        return plain.equals("snob");
    }

    public boolean isRetimeUnit() {
        String plain = getPlainName();
        if (plain == null) {
            return false;
        }
        return !plain.equals("spy") && !plain.equals("snob") && !plain.equals("militia");
    }

    public double getBuildTime() {
        return buildTime;
    }

    public void setBuildTime(double buildTime) {
        this.buildTime = buildTime;
    }

    public String toBBCode() {
        return "[unit]" + getPlainName() + "[/unit]";
    }

    @Override
    public String toString() {
        return getName();// + "(" + getSpeed() + " Minuten/Feld)";
    }

    public static void main(String[] args) {
    }
}
